package com.huamao.niceman.scrollviewpager.home.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.huamao.niceman.scrollviewpager.R;
import com.huamao.niceman.scrollviewpager.base.BaseActivity;
import com.huamao.niceman.scrollviewpager.widget.DepthPageTransformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by LuanXianSheng on 2017/6/15.
 */

public class ConstellationActivity extends BaseActivity {

    @BindView(R.id.consrellation_viewpagerchange)
    ViewPager mViewpager;
    private List<Integer> img = Arrays.asList(R.drawable.long1,R.drawable.long2,R.drawable.long1,R.drawable.long2) ;
    private List<View> iv = new ArrayList<>() ;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_constellation);
        ButterKnife.bind(this);
        initView();
        initData();
        initViewOper();
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        mViewpager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return img.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(iv.get(position));
                return iv.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(iv.get(position));
            }
        });
        mViewpager.setPageTransformer(true,new DepthPageTransformer());
    }

    @Override
    public void initViewOper() {

        for (int imgId:img){
            View layout = getLayoutInflater().inflate(R.layout.constellation_contant,null) ;
            ImageView ivs = (ImageView) layout.findViewById(R.id.contant_iv);
            ivs.setImageResource(imgId);
            iv.add(layout);
        }
    }
}
